﻿using System.Xml.Serialization;

namespace Flowertwig.Utils.Entities
{
    public class SerializableKeyValuePair<TKey, TValue>
    {
        protected bool _changeKey;
        protected bool _changeValue;

        protected TKey _key;
        protected TValue _value;

        [XmlAttribute(AttributeName = "Key")]
        public TKey Key
        {
            get { return _key; }
            set
            {
                if (!_changeKey) return;
                _key = value;
                _changeKey = false;
            }
        }
        [XmlAttribute(AttributeName = "Value")]
        public TValue Value
        {
            get { return _value; }
            set
            {
                if (_changeValue)
                {
                    _value = value;
                    _changeValue = false;
                }
            }
        }

        public SerializableKeyValuePair() { /* Dummy for serialization */ _changeKey = true; _changeValue = true; }

        public SerializableKeyValuePair(TKey key, TValue value)
        {
            _key = key;
            _value = value;
        }
    }
}
